const express = require('express');
const app = express();
const port = 9999;

app.post('/server', (request, response) => {
    // 设置跨域，必须设置
    response.setHeader('Access-Control-Allow-Origin', '*');
    const date = new Date()
    response.send('Ajax Post 请求:' + date.getTime());
})

// 设置了接收任何请求头，请求方式需要使用all，浏览器不会发送get或post请求，而是另外一种请求Options
app.all('/server', (request, response) => {
    // 设置跨域，必须设置
    response.setHeader('Access-Control-Allow-Origin', '*');
    // 设置接收任何请求头
    response.setHeader('Access-Control-Allow-Headers', '*');

    const date = new Date()
    response.send('Ajax Post 请求:' + date.getTime());
})

app.listen(port, () => {
    console.log('正在监听端口号：' + port);
})